/*
 * MoveAnchorPointAction.java
 * 
 * Created by demory on Oct 23, 2009, 8:58:48 PM
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.fpdev.apps.cart.actions;

import java.awt.geom.Point2D;
import org.fpdev.apps.cart.Cartographer;
import org.fpdev.apps.cart.Editor;
import org.fpdev.apps.cart.network.AnchorPoint;

/**
 *
 * @author demory
 */
public class MoveAnchorPointAction extends EditorBasedAction {

  private AnchorPoint anchor_;
  private Point2D.Double from_, to_;

  public MoveAnchorPointAction(Editor ed, AnchorPoint anchor, Point2D.Double from, Point2D.Double to) {
    super(ed);
    anchor_ = anchor;
    from_ = from;
    to_ = to;
  }

  public boolean doAction(Cartographer cart) {
    anchor_.moveTo(to_.getX(), to_.getY());
    ed_.getDocument().getNetwork().rebundle();
    return true;
  }

  public boolean undoAction(Cartographer cart) {
    anchor_.moveTo(from_.getX(), from_.getY());
    ed_.getDocument().getNetwork().rebundle();
    return true;
  }

  public String getName() {
    return "Move Anchor Point";
  }

}
